using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace IllSoft.Xvcc.Volano.Client
{
    /// <summary>
    /// Mimics Java's DataInputStream
    /// </summary>
    internal class VolanoReader : BinaryReader
    {
        public VolanoReader(Stream input)
            : base(input)
        {
        }

        public VolanoReader(Stream input, Encoding encoding)
            : base(input, encoding)
        {
        }

        public string ReadHandle()
        {
            return Convert.ToBase64String(base.ReadBytes(3));
        }

        public int ReadLength()
        {
            return (int)(base.ReadByte() * 0x100 + base.ReadByte());
        }

        public override string ReadString()
        {
            int length = this.ReadLength();

            if (length > 0)
            {
                return Encoding.UTF8.GetString(base.ReadBytes(length));
            }
            else
            {
                return string.Empty;
            }
        }
    }
}